<template>
	<view class="Order bac_f8f8f8">
		<!-- <addressChoose></addressChoose> -->
        
		<view class="order_data marginT_20" >
			<view class="title_img">
				<image v-if="shopping.files" :src="Resource_url + shopping.files.split(',')[0]" mode=""></image>
			</view>
			<view class="title_right">
				<view class="order_title">{{shopping.title}}</view>
				<view class="title_num display_between">
					<view class="title_quantity">
						<view class="title_text">
							<text>{{ spInfo.title }}</text>
						</view>
						<view class="title_price">

							<text>{{shopping.price}}</text>
							<text>积分</text>
						</view>
					</view>
					<!-- <Box @values="values"></Box> -->
                    <u-number-box v-model="value" :max="spInfo.sum"></u-number-box>
				</view>
			</view>
		</view>
		<!-- <view class="borders"></view> -->

		<!-- <view class="borders"></view> -->
		<!-- <view class="Remarks">
			<view class="Remarks_title display_between">
				<text>备注</text>
				<text>8/45</text>
			</view>
			<view class="Remarks_input">
				<u--input placeholder="选填,留言给商家" border="none" v-model="input_value"></u--input>
			</view>
		</view> -->

		<view class="payment bac_ffffff">
			<view class="payment_integral display_between">
				<text>积分</text>
				<text>您当前剩余{{users.integral}}积分</text>
			</view>
			<!-- <view class="payment_integral display_between">
				<text>支付方式</text>
				<view class="">
					<u-radio-group v-model="radiovalue1" placement="row">
						<u-radio :customStyle="{marginBottom: '8px',marginLeft:'30rpx'}"
							v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.name">
						</u-radio>
					</u-radio-group>
				</view>
			</view> -->
			<!-- <view class="payment_integral display_between integral">
				<view class="">
					<text>积分抵扣</text>
					<text>共5000，可用3000，抵￥30</text>
				</view>
				<view class="radio" @click="setBut()">
					<text :class="value1?'style_radio1':'style_radio2'"></text>
				</view>
			</view> -->
		</view>

		<view class="Order_but bac_ffffff display_between">
			<view class="but_right">
				<!-- <text>￥</text> -->
				<text>{{zong_price}}</text>
				<text>积分</text>
			</view>
			<view class="but_text but_B29062 display_center" @click="confirm">
				提交订单
			</view>
		</view>
		<u-modal :show="show" :showCancelButton="true" title="确认提醒" content='是否确认下单' @cancel="show=false"
			@confirm="addOrder"></u-modal>
		<u-toast ref="uToast" zIndex="9999999"></u-toast>
	</view>
</template>

<script>
    import {
        specification_id_one_inte,
        integral_order_add_json,
        integral_product_id
    } from "@/api/useryk.js"
    import {Resource_url, Http_url} from "@/config/config.js"
	import Box from "@/components/NumberBox/NumberBox.vue";
	//引入请求接口
	// import commodity from "@/libs/api/commodity.js"
	// import member from "@/libs/api/member";
	// import address from "@/libs/api/address";
	export default {
		data() {
			return {
                Resource_url,
				// radiolist1: [{
				// 		name: '微信',
				// 		disabled: false
				// 	},
				// 	{
				// 		name: '余额',
				// 		disabled: false
				// 	}
				// ],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				// radiovalue1: '苹果',
				// value1: true,
				user: {}, //用户下单信息
				shopping: {}, //指定商品信息
				value: 1, //数字选择框
				input_value: '', //input框数据
				users_data: {
					pr_id: 1,
					token: '',
					sp_id: 1,
					sum: 1,
					user_id: 1,
					address_id: ''
				},
				Member: {
					token: '',
					user_id: 1
				},

				// add: {
				// 	token: '',
				// 	user_id: 1
				// },
				add_data: {},
				show: false,
				timer: null,
                // 商品id
                id: '',
                // 规格id
                spid: '',
                // 
                spInfo: {}
			}
		},
		onLoad(params) {
            
            this.id = params.id
            this.spid = params.spid
            this.value = params.num
            
            this.getData()
            this.setCommodity()
            // this.setMember()

			// this.user = this.$u.vuex.get('user.shop')
			// this.users_data.pr_id = this.user.userId
			// this.users_data.sp_id = this.user.typeID
			// this.users_data.sum = this.user.value
			// console.log(this.interData, 'interData');
			// this.shopping = this.$u.vuex.get('user.interData')
			// this.users_data.user_id = this.$u.vuex.get('user.userInfo').user_id
		},
        onShow() {
            this.$store.dispatch('USERINFO')
        },
		computed: {
			zong_price() {
				// console.log(this.value, this.shopping, 'ccc');
				return this.value * this.shopping.price
			},
            users(){
                return this.$store.state.app.userInfou || {}
            }
		},
		methods: {
            getData(){
                integral_product_id({
                	id: this.id
                }).then(res => {
                    this.shopping = res.data
                })
                // 规格信息
                specification_id_one_inte({
                	id: this.spid
                }).then(res => {
                    this.spInfo = res.data
                })
            },
			setBut() {
				this.value1 = !this.value1
			},

			//根据id获取积分信息
			setCommodity() {
				// this.$u.request('member.orderId', {
				// 	id: this.shopping.id
				// }).then(res => {
				// 	console.log(res, 'sss');
				// 	let interData = {
				// 		...res.data,
				// 		files:this.$imgurl(res.data.files) 
				// 		// this.$evns + res.data.files
				// 	}
				// 	this.$u.vuex.set('user.interData', interData)
				// 	// this.index_lenght = this.shopping.files.length
				// 	// console.log(this.shopping, 'productId');
				// })
			},
			confirm() {
				this.show = true
			},
			addOrder() {
	

				if (this.zong_price < this.users.integral) {
                    
                    if(this.loading) {
                        return
                    }
                    this.loading = true
                    
                    let parmas = {
                        pr_id: this.id,
                        sp_id: this.spid,
                        sum: this.value,
                        user_id: this.users.id
                        // address_id: this.$u.vuex.get('user.selectAddress.id'),
                    }
                    
					integral_order_add_json( parmas).then(res => {
						this.show = false
						if (res.code == 900) {
							this.$refs.uToast.show({
								type: 'success',
								message: '下单成功',
								duration: '500',
								complete: () => {
									uni.$u.route({
                                        url: '/pages/integral/orderList',
                                        type: 'redirectTo'
                                    });
								}
							})
						} else {
							this.$refs.uToast.show({
								type: 'error',
								message: res.message
							})
						}
                        setTimeout(() => { 
                            this.loading = false
                        }, 2000)
					}).catch(err => {
                        this.loading = false
                    })
                    
				} else {
                    this.show = false
					this.$refs.uToast.show({
						type: 'error',
						message: "积分不足"
					})
				}
			},
			

			//修改地址
			setAdds() {
				// uni.navigateTo({
				// 	url: "/pages/Points/address/address"
				// })
				uni.$u.route('/pages/Points/address/address');
			},
			values(a) {
				console.log(a, 'aaa');
				this.value = a
				this.users_data.sum = a
			}
		},
		components: {
			Box
		}
	}
</script>

<style scoped lang="scss">
    @import '@/libs/PublicStyle.scss';
	@import "./order.scss";
</style>